<?

require_once './lib/function_development.php';
require_once './lib/Template.php';
require_once './lib/SqliteTriggerGenerator.php';
require_once './lib/geshi/geshi.php';

$tpl =  new Template();

$statement = empty($_POST['statement']) ? '' : $_POST['statement'];
$inc_delete = !empty($_POST['inc_delete']);
$inc_create = !empty($_POST['inc_create']);

if( empty( $statement ) ) {
    $tpl->set( 'show_results', false );
} else {
    $tpl->set( 'show_results', true );
    
    $gen = new SqliteTriggerGenerator( $inc_delete, $inc_create );
    
    $sql = $gen->create( $statement );
    
    $sql_html = '';
    foreach( $sql as $statement ) {
        $geshi = new GeSHi($statement, 'sql');
        $geshi->set_header_type(GESHI_HEADER_DIV);
        $sql_html .= $geshi->parse_code();
    }
    
    $tpl->set( 'result_sql', $sql_html );
}

echo $tpl->fetch('index.html');

?>

